package cm.fw.log;

import java.lang.reflect.Method;

import org.apache.log4j.Logger;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice;

public class LoggerAdvicer implements MethodBeforeAdvice, AfterReturningAdvice {

    static Logger logger = Logger.getLogger("test1");

    @Override
    public void before(Method method, Object[] args, Object target)
            throws Exception {
        if (target != null) {
            String targetStr = String.valueOf(target);
            logger.info("Start Message :==> " + targetStr.substring(0, targetStr.indexOf("@"))
                    + "." + method.getName() + "()");
        }
    }

    @Override
    public void afterReturning(Object returnVal, Method method, Object[] args, Object target)
            throws Exception {
        if (target != null) {
            String targetStr = String.valueOf(target);
            logger.info("End Message :==> " + targetStr.substring(0, targetStr.indexOf("@")) + "."
                    + method.getName() + "()");
        }
    }
}
